package jp.ne.hatena.d.digitalsoul.warikan.actions

import java.io._
import java.text._

import jp.ne.hatena.d.digitalsoul.warikan.contexts._
import jp.ne.hatena.d.digitalsoul.warikan.pages.forms._
import jp.ne.hatena.d.digitalsoul.warikan.repositories._

class PayingAction extends Serializable {
	
	val format = new SimpleDateFormat("yyyy/MM/dd")
	
	def createMainForm(partyId:String) = {
		
		val mainFormModel = new PayingMainForm
		val partyOption = PartyRepository.forPartyId(partyId)
		if (partyOption.isDefined) {
			val party = partyOption.get
			mainFormModel.partyName  = party.name
			mainFormModel.schedule  = format.format(party.schedule)
			mainFormModel.location = party.location
			mainFormModel.fee = party.sum
		}
		mainFormModel
	}
	
	
	def pay(partyId:String, fee:Int) = {
		val paying:Paying = new Paying(partyId)
		paying.pay(fee)
		paying.commit
	}

}